package com.company.笔试.发牌程序;

import java.util.HashMap;
import java.util.Random;

/**
 * @ClassName SendCard
 * @Description
 *  　　  黑桃按照从小到大依次为：1-13  ♡♢♤♧
 *
 * 　　　红桃按照从小到大依次为：14-26
 *
 * 　　　梅花按照从小到大依次为：27-39
 *
 * 　　　方块按照从小到大依次为：40-52
 * @Author 11
 * @Date 2021/4/6 17:00
 * @Version 1.0
 */
public class SendCard extends Player{

    public static HashMap<Integer,String> cardMap=new HashMap<>();
    public static int [] total=new int[52];//52张牌
    public static String[] cardNums = {"K","2","3","4","5","6","7","8","9","10","J","Q","A"};
    static {
        for (int i = 0; i < total.length; i++) {    //将牌数设在1--52之间 其中1~13表示一种花色
            int num = i+1;
            total[i]= num;                        //，依此类推
            if (num>=1 && num <=13){
                cardMap.put(num,"♢");
            }else if (num>=14 && num <=26){
                cardMap.put(num,"♧");
            }else if (num>=27 && num <=39){
                cardMap.put(num,"♡");
            }else if (num>=40 && num <=52){
                cardMap.put(num,"♤");
            }
        }
    }

//    private int[][]player = new int[4][13];//玩家
    private int[][]player = getPlayer();//玩家

    public SendCard (){
        int leftNum=52;        //剩下的牌数
        int ranNumber;            //随机发的牌
        Random random=new Random();
        for(int i=0;i<player[0].length;i++){        //随机分配牌
            for(int j=0;j<player.length;j++){
                ranNumber=random.nextInt(leftNum);        //随机获取下标，  剩余leftNum 牌数
                player[j][i]=total[ranNumber];            //将随机的数赋给玩家
                total[ranNumber] = total[leftNum-1];   //除去发出去的牌，用【leftNum-1】覆盖
                leftNum--;
            }
        }
        setPlayer(player);
    }

//    public int[][] getPlayer() {
//        return player;
//    }
//    public void setPlayer(int[][] player) {
//        this.player = player;
//    }

    public void Show() {
        for (int i = 0; i < getPlayer().length; i++) {
            System.out.print("玩家"+(i+1)+"的牌");
            for (int j = 0; j < getPlayer()[i].length; j++) {
//                System.out.print(" "+getPlayer()[i][j]);
                int nums = getPlayer()[i][j];
                System.out.print(" "+cardMap.get(nums)+cardNums[nums%13]);
            }
            System.out.println();
        }
    }



    public static void main(String[] args) {
        System.out.println("开始发牌！");
        SendCard sendCard = new SendCard();
        System.out.println("展示！");
        sendCard.Show();
    }

}
